package com.hzhk.happyrent.ui.adapter.bill;

import android.content.Context;
import android.text.TextUtils;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.hzhk.happyrent.R;
import com.hzhk.happyrent.bean.bill.ProductBillBean;
import com.hzhk.happyrent.ui.activity.bill.BillListActivity;
import com.hzhk.happyrent.ui.adapter.BaseAdapter;
import com.hzhk.happyrent.utils.TimeUtil;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by ss on 2018/1/23.
 */

public class ProductBillAdapter extends BaseAdapter<ProductBillBean.DataBean.OrdersBean> {
    public ProductBillAdapter(Context context) {
        super(context);
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder;
        if (convertView == null) {
            convertView = mInflater.inflate(R.layout.item_product_bill,
                    null);
            viewHolder = new ViewHolder(convertView);
            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }
        viewHolder.setData(getItem(position));
        return convertView;
    }

    class ViewHolder {
        @BindView(R.id.item_pay)
        TextView itemPay;
        @BindView(R.id.pay_for)
        TextView payFor;
        @BindView(R.id.item_pay_law)
        TextView itemPayLaw;
        @BindView(R.id.item_pay_periods)
        TextView itemPayPeriods;
        @BindView(R.id.expire_pay_money)
        TextView expirePayMoney;

        ViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
        public void setData(final ProductBillBean.DataBean.OrdersBean ordersBean){
            itemPay.setText("￥"+ordersBean.getMoney());
            if("1".equals(ordersBean.getStatus())){
                payFor.setText("已交租");
                payFor.setTextColor(mContext.getResources().getColor(R.color.black_20));
            }else if("0".equals(ordersBean.getStatus())){
                payFor.setText("待交租");
                payFor.setTextColor(mContext.getResources().getColor(R.color.black_40));
            }else{
                payFor.setText("待交租");
                payFor.setTextColor(mContext.getResources().getColor(R.color.tab_red_80));
            }
            if(!TextUtils.isEmpty(ordersBean.getExpirePayMoney())){
                expirePayMoney.setVisibility(View.VISIBLE);
                expirePayMoney.setText("+"+ordersBean.getExpirePayMoney()+"(违约金)");
            }else{
                expirePayMoney.setVisibility(View.GONE);
            }
            itemPayLaw.setText("交租日期："+ TimeUtil.getStrTimeYMD(ordersBean.getEndTime()));
            itemPayPeriods.setText("第"+ordersBean.getPeriods()+"期");
        }
    }
}
